package com.lock.test.config;

import org.redisson.Redisson;
import org.redisson.codec.JsonJacksonCodec;
import org.redisson.config.Config;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author: alexxiao
 * @date: 2023/3/8 11:30
 * <p>
 */
@Configuration
public class RedissonConfig {

    @Autowired
    private RedisConfiguration redisConfiguration;

    @Bean
    public Redisson redisson() {
        Config config = new Config();
        config.useSingleServer().setAddress("redis://" + redisConfiguration.getHost() + ":" + redisConfiguration.getPort())
                .setClientName(redisConfiguration.getUsername())
                .setPassword(redisConfiguration.getPassword())
                .setDatabase(redisConfiguration.getDatabase());
        config.setCodec(new JsonJacksonCodec());
        return (Redisson) Redisson.create(config);
    }
}